//
// Created by liuhuan on 2022/5/14.
//

#ifndef RUIYAN_PTZ_REGISTER_H
#define RUIYAN_PTZ_REGISTER_H

#include <jni.h>

// 对应 BoundingBox 类
typedef struct BoundingBox_block_t {
    jclass clazz;
    jmethodID constructor;
    jfieldID classId;
    jfieldID xmin;
    jfieldID ymin;
    jfieldID xmax;
    jfieldID ymax;
    jfieldID score;
} BoundingBox_block;

// 对应 DetectParams 类
typedef struct DetectParams_block_t {
    jclass clazz;
    jmethodID constructor;
    jfieldID detectObjThres;
    jfieldID detectMinBBoxSize;
} DetectParams_block;

// 对应 DeviceInfo 类
typedef struct DeviceInfo_block_t {
    jclass clazz;
    jmethodID constructor;
    jfieldID no;
    jfieldID camType;
    jfieldID port;
    jfieldID devStatus;
} DeviceInfo_block;

// 对应 DeviceInfo 类
typedef struct PidInfo_block_t {
    jclass clazz;
    jmethodID constructor;
    jfieldID p;
    jfieldID i;
    jfieldID d;
} PidInfo_block;

// 对应 SkyNodeGndAlgParams 类
typedef struct SkyNodeGndAlgParams_block_t {
    jclass clazz;
    jmethodID constructor;
    jfieldID devNo;
    jfieldID detectParams;
    jfieldID trackParam;
} SkyNodeGndAlgParams_block;

// 对应 SkyNodeGndBaseInfo 类
typedef struct SkyNodeGndBaseInfo_block_t {
    jclass clazz;
    jmethodID constructor;
    jfieldID currentMode;
    jfieldID ptzStatus;
    jfieldID yaw;
    jfieldID pitch;
    jfieldID roll;
    jfieldID rangeValid;
    jfieldID rangVal;
    jfieldID mainZoom;
} SkyNodeGndBaseInfo_block;

// 对应 SkyNodeGndDetectInfoS 类
typedef struct SkyNodeGndDetectInfoS_block_t {
    jclass clazz;
    jmethodID constructor;
    jfieldID devNo;
    jfieldID camLensType;
    jfieldID zoom;
    jfieldID boxLen;
    jfieldID boxes;
} SkyNodeGndDetectInfoS_block;

// 对应 SkyNodeGndDevice 类
typedef struct SkyNodeGndDevice_block_t {
    jclass clazz;
    jmethodID constructor;
    jfieldID isRanging;
    jfieldID devNums;
    jfieldID deviceInfos;
} SkyNodeGndDevice_block;

// 对应 SkyNodeGndPTZPid 类
typedef struct SkyNodeGndPTZPid_block_t {
    jclass clazz;
    jmethodID constructor;
    jfieldID pitchP;
    jfieldID pitchI;
    jfieldID pitchD;
    jfieldID yawP;
    jfieldID yawI;
    jfieldID yawD;
} SkyNodeGndPTZPid_block;

// 对应 SkyNodeGndTrackInfo 类
typedef struct SkyNodeGndTrackInfo_block_t {
    jclass clazz;
    jmethodID constructor;
    jfieldID devNo;
    jfieldID camLensType;
    jfieldID zoom;
    jfieldID destIsLost;
    jfieldID box;
    jfieldID dstAndCenterAngleX;
    jfieldID dstAndCenterAngleY;
    jfieldID yaw;
    jfieldID pitch;
    jfieldID roll;
} SkyNodeGndTrackInfo_block;

// 对应 TrackParams 类
typedef struct TrackParams_block_t {
    jclass clazz;
    jmethodID constructor;
    jfieldID searchSize;
    jfieldID tmplSize;
    jfieldID srcWidth;
    jfieldID srcHeight;
    jfieldID thresholdLow;
    jfieldID thresholdHigh;
    jfieldID longtermSearchSize;
} TrackParams_block;

// 对应 ArrayList 类
typedef struct ArrayList_block_t {
    jclass clazz;
    jmethodID constructor;
    jmethodID add;
} ArrayList_block;

class Register {
public:
    static Register *getInstance() {
        static Register instance;
        return &instance;
    }

// 注册
    void register_classes(JNIEnv *env);

    const BoundingBox_block &getBoxBlock() const;

private:
    int find_class(JNIEnv *env, const char *name, jclass *clazz_out);

    int
    get_field(JNIEnv *env, jclass *clazz, const char *name, const char *sig, jfieldID *field_out);

    void registerList(JNIEnv *env);

    void registerBoundingBox(JNIEnv *env);

    void registerDetectParams(JNIEnv *env);

    void registerDeviceInfo(JNIEnv *env);

    void registerPidInfo(JNIEnv *env);

    void registerSkyNodeGndAlgParams(JNIEnv *env);

    void registerSkyNodeGndBaseInfo(JNIEnv *env);

    void registerSkyNodeGndDetectInfoS(JNIEnv *env);

    void registerSkyNodeGndDevice(JNIEnv *env);

    void registerSkyNodeGndPTZPid(JNIEnv *env);

    void registerSkyNodeGndTrackInfo(JNIEnv *env);

    void registerTrackParams(JNIEnv *env);

private:
    BoundingBox_block boxBlock;
    DetectParams_block detectParamsBlock;
    DeviceInfo_block deviceInfoBlock;
    PidInfo_block pidInfoBlock;
    SkyNodeGndAlgParams_block algParamsBlock;
    SkyNodeGndBaseInfo_block baseInfoBlock;
    SkyNodeGndDetectInfoS_block detectInfoSBlock;
    SkyNodeGndDevice_block deviceBlock;
    SkyNodeGndPTZPid_block ptzPidBlock;
    SkyNodeGndTrackInfo_block trackInfoBlock;
    TrackParams_block trackParamsBlock;
    ArrayList_block listBlock;
};


#endif //RUIYAN_PTZ_REGISTER_H
